/*
 * 各种通知信息判断
 * */
import { ElMessage, ElNotification } from 'element-plus'

/**
 * 自定义弹出框-内核ElNotification。
 * @param {string} title 消息头
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 */
export const oops = (title: string, message: string, type: string) => {
  if (type == 'success' || type == 's' || type == '成功' || type == '绿色') {
    ElNotification.success({
      title: title,
      message: message,
      position: 'bottom-right'
    })
  } else if (
    type == 'warning' ||
    type == 'w' ||
    type == '警告' ||
    type == '黄色' ||
    type == '危险'
  ) {
    ElNotification.warning({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: 8000
    })
  } else if (type == 'error' || type == 'e' || type == 'bug' || type == '红色' || type == '错误') {
    ElNotification.error({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: 12000
    })
  } else if (type == 'AmapInfoWindow' || type == '信息窗体' || type == 'html') {
    AmapInfoWindow(title, message)
  } else {
    ElNotification.info({
      title: title,
      message: message,
      position: 'bottom-right'
    })
  }
}

/**
 * 自定义弹出框-内核ElNotification。
 * @param {string} title 消息头
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 * @param {string} duration 默认情况-1=4.5秒后自动关闭,0=不自动关闭,其他=自动关闭秒数
 */
export const oopsTime = (title: string, message: string, type: string, duration: number) => {
  if (duration == -1) {
    duration = 4500
  } else if (duration != 0) {
    duration *= 1000
  }

  if (type == 'success' || type == 's' || type == '成功' || type == '绿色') {
    ElNotification.success({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: duration
    })
  } else if (
    type == 'warning' ||
    type == 'w' ||
    type == '警告' ||
    type == '黄色' ||
    type == '危险'
  ) {
    ElNotification.warning({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: duration
    })
  } else if (type == 'error' || type == 'e' || type == 'bug' || type == '红色' || type == '错误') {
    ElNotification.error({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: duration
    })
  } else if (type == 'AmapInfoWindow' || type == '信息窗体' || type == 'html') {
    AmapInfoWindow(title, message)
  } else {
    ElNotification.info({
      title: title,
      message: message,
      position: 'bottom-right',
      duration: duration
    })
  }
}

/**
 * 定制化-指定位置和停留时间
 * @param {string} title 消息头
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 * @param {string} pos position 右上、右下、左上、左下,空字符串默认（右下角）
 * @param {string} duration 默认情况-1=4.5秒后自动关闭,0=不自动关闭,其他=自动关闭秒数
 */
export const oopsPosition = (
  title: string,
  message: string,
  type: string,
  pos: string,
  duration: number
) => {
  let position: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
  if (pos == '右上' || pos == 'top-right' || pos == 'tr') {
    position = 'top-right'
  } else if (pos == '右下' || pos == 'bottom-right' || pos == 'br') {
    position = 'bottom-right'
  } else if (pos == '左上' || pos == 'top-left' || pos == 'tl') {
    position = 'top-left'
  } else if (pos == '左下' || pos == 'bottom-left' || pos == 'bl') {
    position = 'bottom-left'
  } else if (pos == '') {
    position = 'bottom-right'
  } else {
    position = 'bottom-right'
  }

  if (duration == -1) {
    duration = 4500
  } else if (duration != 0) {
    duration *= 1000
  }

  if (type == 'success' || type == 's' || type == '成功' || type == '绿色') {
    ElNotification.success({
      title: title,
      message: message,
      position: position,
      duration: duration
    })
  } else if (
    type == 'warning' ||
    type == 'w' ||
    type == '警告' ||
    type == '黄色' ||
    type == '危险'
  ) {
    ElNotification.warning({
      title: title,
      message: message,
      position: position,
      duration: duration
    })
  } else if (type == 'error' || type == 'e' || type == 'bug' || type == '红色' || type == '错误') {
    ElNotification.error({
      title: title,
      message: message,
      position: position,
      duration: duration
    })
  } else if (type == 'AmapInfoWindow' || type == '信息窗体' || type == 'html') {
    AmapInfoWindow(title, message)
  } else {
    ElNotification.info({
      title: title,
      message: message,
      position: position,
      duration: duration
    })
  }
}

/**
 * 定制化-打开一个链接
 * @param {string} title 消息头
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 * @param {string} pos position 右上、右下、左上、左下,空字符串默认（右下角）
 * @param {string} duration 默认情况-1=4.5秒后自动关闭,0=不自动关闭,其他=自动关闭秒数
 */
export const OpenHtml = (
  title: string,
  message: string,
  type: string,
  pos: string,
  duration: number
) => {
  let position: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
  if (pos == '右上' || pos == 'top-right' || pos == 'tr') {
    position = 'top-right'
  } else if (pos == '右下' || pos == 'bottom-right' || pos == 'br') {
    position = 'bottom-right'
  } else if (pos == '左上' || pos == 'top-left' || pos == 'tl') {
    position = 'top-left'
  } else if (pos == '左下' || pos == 'bottom-left' || pos == 'bl') {
    position = 'bottom-left'
  } else if (pos == '') {
    position = 'bottom-right'
  } else {
    position = 'bottom-right'
  }

  if (duration == -1) {
    duration = 4500
  } else if (duration != 0) {
    duration *= 1000
  }

  if (type == 'success' || type == 's' || type == '成功' || type == '绿色') {
    ElNotification.success({
      title: title,
      message: message,
      dangerouslyUseHTMLString: true,
      position: position,
      duration: duration
    })
  } else if (
    type == 'warning' ||
    type == 'w' ||
    type == '警告' ||
    type == '黄色' ||
    type == '危险'
  ) {
    ElNotification.warning({
      title: title,
      message: message,
      dangerouslyUseHTMLString: true,
      position: position,
      duration: duration
    })
  } else if (type == 'error' || type == 'e' || type == 'bug' || type == '红色' || type == '错误') {
    ElNotification.error({
      title: title,
      message: message,
      dangerouslyUseHTMLString: true,
      position: position,
      duration: duration
    })
  } else {
    ElNotification.info({
      title: title,
      message: message,
      dangerouslyUseHTMLString: true,
      position: position,
      duration: duration
    })
  }
}

/**
 * 定制化-打开一个链接(下载等)
 * @param {string} title 消息头
 * @param {string} api url地址
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 * @param {string} pos position 右上、右下、左上、左下,空字符串默认（右下角）
 * @param {string} duration 默认情况-1=4.5秒后自动关闭,0=不自动关闭,其他=自动关闭秒数
 */
export const oopsUrl = (
  title: string,
  api: string,
  message: string,
  type: string,
  pos: string,
  duration: number
) => {
  if (message == '') message = api
  message = '<a href="' + api + '" target="_blank">' + message + '</a>'
  OpenHtml(title, message, type, pos, duration)
}

//搭建自定义窗体【使用 HTML 片段作为正文内容】
export const AmapInfoWindow = (title: string, message: string) => {
  ElNotification({
    title: title,
    message: message,
    dangerouslyUseHTMLString: true,
    type: '',
    duration: 0,
    position: 'top-right', //'top-right' | 'top-left' | 'bottom-right' | 'bottom-left',
    showClose: true,
    offset: 0,
    zIndex: 0
  })
}

/**
 * 自定义弹出框-内核ElMessage。
 * @param {string} title 消息头
 * @param {string} message 消息内容
 * @param {string} type success(s,成功,绿色)、warning(w,警告,黄色,危险)、error(e,bug,红色，错误)，其他默认info
 */
export const msg = (title: string, message: string, type: string) => {
  if (type == 'success' || type == 's' || type == '成功' || type == '绿色') {
    ElMessage.success({
      message: `【${title}】` + message,
      plain: true
    })
  } else if (
    type == 'warning' ||
    type == 'w' ||
    type == '警告' ||
    type == '黄色' ||
    type == '危险'
  ) {
    ElMessage.warning({
      message: `【${title}】` + message
    })
  } else if (type == 'error' || type == 'e' || type == 'bug' || type == '红色' || type == '错误') {
    ElMessage.error({
      message: `【${title}】` + message
    })
  } else {
    ElMessage.info({
      message: `【${title}】` + message
    })
  }
}
